Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework: Pass editor initial settings as direct argument #9921

Merged
merged 1 commit into from
Sep 17, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Sep 14, 2018

Extracted from #9403

This pull request refactors server-side editor initialization to pass initial edits as a setting directly to the editor initialization, rather than by proxy through a window._wpGutenbergDefaultPost global. In doing so, it resolves a yet-undiscovered issue where our filtering of the_title was effectively disregarded, since we never used the rendered property of the title populating the editor. This will be further separately improved by efforts in #9403.

Related to these future efforts, I think we should consider demo content as an external influencer, exposing filters necessary to provide these initial edits, in a similar fashion to what exists already with the block_editor_settings filter. Here's a patch which, when applied to this branch, would achieve this. However, I am choosing to defer this to after #9403, as it is not my desire for the raw / rendered distinction of content attributes persist, and thus be exposed into a public interface for extending initial edits.

Testing instructions:

Verify there are no regressions in the behavior of initial edits, notably:

  • Demo post title and content
  • Editing an existing post
  • New post with and without the_title filter

Here's a small plugin for testing the_title:

<?php

/**
 * Plugin Name: Filter The Title
 */

add_filter( 'the_title', function() {
	return 'My default title';
} );

(Note: the_title is not an editor-specific filter, so it will have additional side-effects to leave the above plugin activated after testing)

@aduth aduth added the Framework Issues related to broader framework topics, especially as it relates to javascript label Sep 14, 2018
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@aduth
Copy link
Member Author

aduth commented Sep 17, 2018

For transparency's sake, I should note that there's technically a breaking change here in that we no longer expose the _wpGutenbergDefaultPost global which would have been previously available and perhaps an option for other plugin's to manipulate values of the post before initialization. While this was never officially supported and the name of the global itself (with underscore prefixing and Gutenberg codename) could serve as a hint to its being an internal-global, we've had some precedent elsewhere of encouraging use of these globals (more specifically, the _wpLoadGutenbergEditor promise). At the very least, we should stop encouraging their use, as even for this latter global we'll want to at least remove reference to "Gutenberg" in its name.

As mentioned in the original comment, there is certainly intention to make overriding initial values part of the public interface, likely through a new block_editor_initial_edits PHP filter, but this will first require additional changes as explored in #9403.

@aduth aduth added this to the 4.0 milestone Sep 17, 2018
@aduth aduth merged commit cd6ae73 into master Sep 17, 2018
@aduth aduth deleted the fix/the-title-filter branch September 17, 2018 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants